import { preload, load } from '@/api/bizApi'

export const useBizStore = (name) => {
  return defineStore(name, {
    state: () => ({
      activeTab: '',
      tabs: [],
      buttons: [],
      caseMessage: {},
      materialTab: {}
    }),
    actions: {
      preload(data) {
        preload(data).then((res) => {
          const { tabs = [], buttons = [], activeTab } = res
          this.tabs = tabs
          this.buttons = buttons
          this.activeTab = activeTab
        })
      },
      load(data) {
        load(data).then((res) => {
          for (let key in res) {
            this[key] = res[key]
          }
        })
      },
      setTab(name, data) {
        this[name] = data
      }
    }
  })
}
